// 申请管理
<template>
  <div class="mod-apply">
    <el-select
      v-model="nickName"
      placeholder="请选择申请人"
      clearable
      @change="monthChange()"
    >
      <el-option
        v-for="item in options"
        :key="item.userId"
        :label="item.nickName"
        :value="item.userId"
      >
      </el-option>
    </el-select>
    <el-select
      v-model="applyStatus"
      placeholder="请选择状态"
      clearable
      @change="monthChange()"
    >
      <el-option
        v-for="item in options1"
        :key="item.value"
        :label="item.name"
        :value="item.value"
      >
      </el-option>
    </el-select>

    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%; margin-top: 1vw"
    >
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50"
      >
      </el-table-column>
      <el-table-column
        prop="nick_name"
        header-align="center"
        align="center"
        label="申请人"
      >
      </el-table-column>
      <el-table-column
        prop="apply_date"
        header-align="center"
        align="center"
        label="申请日期"
      >
      </el-table-column>
      <el-table-column
        prop="apply_type"
        header-align="center"
        align="center"
        label="申请类型"
      >
      </el-table-column>
      <el-table-column
        prop="apply_reason"
        header-align="center"
        align="center"
        label="申请原因"
      >
      </el-table-column>
      <el-table-column
        prop="apply_status"
        header-align="center"
        align="center"
        label="状态"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.apply_status == 0">待审批</span>
          <span v-else-if="scope.row.apply_status == 1">通过</span>
          <span v-else>未通过</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="apply_remark"
        header-align="center"
        align="center"
        label="备注"
      >
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作"
      >
        <template slot-scope="scope">
          <el-button
            type="success"
            icon="el-icon-check"
            circle
            @click="checkApply(1, scope.row.id)"
          ></el-button>
          <el-button
            type="info"
            icon="el-icon-close"
            circle
            @click="checkApply(2, scope.row.id)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: "apply",
  data() {
    return {
      nickName: "",
      applyStatus: "",
      options: [],
      options1: [
        {
          name: "待审批",
          value: 0,
        },
        {
          name: "通过",
          value: 1,
        },
        {
          name: "未通过",
          value: 2,
        },
        {
          name: "全部",
          value: "",
        },
      ],
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false,
      addOrUpdateVisible: false,
    };
  },
  activated() {
    this.getDataList();
  },
  mounted() {
    this.getPeopleList();
  },
  methods: {
    monthChange() {
      this.getDataList();
    },
    checkApply(val, id) {
      this.$http({
        url: this.$http.adornUrl("/business/eapply/update"),
        method: "post",
        data: this.$http.adornData({
          id: id,
          applyStatus: val,
        }),
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.$message({
            message: "操作成功",
            type: "success",
            duration: 1500,
            onClose: () => {
              this.getDataList();
            },
          });
        } else {
          this.$message.error(data.msg);
        }
      });
    },
    // 人员列表
    getPeopleList() {
      this.$http({
        url: this.$http.adornUrl("/sys/user/list"),
        method: "get",
        params: this.$http.adornParams({
          page: 1,
          limit: 999,
          roleName: "",
        }),
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.options = data.page.list;
        }
      });
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("/business/eapply/query"),
        method: "get",
        params: this.$http.adornParams({
          pageNum: this.pageIndex,
          pageSize: this.pageSize,
          userId: this.nickName,
          applyStatus: this.applyStatus,
        }),
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.records;
          this.totalPage = data.page.total;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val;
    },
  },
};
</script>
